/**
 * 
 */
package com.taobao.wolfwolf.hibernate.dao.impl;

import java.util.List;

import org.hibernate.Hibernate;

import com.taobao.wolfwolf.hibernate.dao.CategoryDao;
import com.taobao.wolfwolf.hibernate.pojo.Category;

/**
 * @author Tux
 *
 * 创建时间: 2011-4-29 上午09:45:11
 */
@SuppressWarnings("unchecked")
public class CategoryDaoImpl extends BaseDaoImpl implements CategoryDao {
	
	public Category findById(int id) throws Exception {
		return (Category) getHibernateTemplate().get(Category.class, id);
	}
	
	public Category findById(boolean lazy, int id) throws Exception {
		Category c = findById(id);
		if(c != null)
			Hibernate.initialize(c.getTypes());
		return c;
	}
	
	public List<Category> findByName(String name) throws Exception {
		return super.findByProperty(Category.class, "name", name);
	}

	public List<Category> findAll() throws Exception {
		return getHibernateTemplate().find("from Category");
	}

	public long getTotal() throws Exception {
		return super.countByCriteria(Category.class);
	}

	public List<Category> paging(int page, int limit) throws Exception {
		return super.findByCriteriaByPage(Category.class, page, limit);
	}
}
